package org.dromara.comm_lhz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsPointsManagementEntity;
import org.dromara.comm_lhz.param.PointsPageParam;
import org.dromara.comm_lhz.service.AsPointsManagementHService;
import org.dromara.comm_lhz.util.Result;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

/**
 * 积分列表
 */
@RestController
@RequestMapping("/pointsManagement")
@AllArgsConstructor
public class AsPointsManagementHController {

    private AsPointsManagementHService asPointsManagementHService;

    /**
     * 根据id分页模糊查询积分
     *
     * @return
     */
    @GetMapping("/selPoints")
    public IPage<AsPointsManagementEntity> selPoints(String nickName, Pageable pageable) {
        return  asPointsManagementHService.selPoints(nickName, pageable);
    }

    /**
     *  新增用户积分信息
     */

    @PostMapping("/savePoints")
    public Result savePoints(@RequestBody AsPointsManagementEntity asPointsManagementEntity) {
        if (asPointsManagementHService.insert(asPointsManagementEntity ) == 1) {
            return Result.success("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }


    /**
     * 增加积分 (根据id修改用户积分)
     * @param asPointsManagementEntity
     * @return
     */
    @PostMapping("/updatePoints")
    public Result updatePoints(@RequestBody AsPointsManagementEntity asPointsManagementEntity) {
        if (asPointsManagementHService.updatePointsById(asPointsManagementEntity)) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    /**
     * 删除积分 逻辑删除
     * @param asPointsManagementEntity
     * @return
     */
    @DeleteMapping("/delPoints")
    public Result delPoints(@RequestBody AsPointsManagementEntity asPointsManagementEntity) {
        if (asPointsManagementHService.removeById(asPointsManagementEntity.getId())) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }



}
